#ifndef _H_C_TASK_HELPER_H_
#define _H_C_TASK_HELPER_H_

#include "STaskProcessor.h"

namespace TB
{
	class CTaskHelper
	{
	public:
		static STask<void> Delay(UINT64 qwMilliSeconds);

		template<typename T>
		static STask<T> Resolve(const T& oData)
		{
			return STask<T>(oData);
		}
		static STask<void> Resolve()
		{
			return STask<void>(true);
		}
		template<typename T>
		static STaskProcessor<T> CreatePendingTask()
		{
			return STaskProcessor<T>(false);
		}

		template<typename T>
		static STask<std::vector<T>> All(const std::vector<STask<T>>& roTasks)
		{
			UINT32 dwSize = (UINT32)roTasks.size();
			std::vector<T> oRetData(dwSize);
			if (dwSize != 0)
			{
				for (UINT32 i = 0; i != dwSize; ++i)
				{
					T t = co_await const_cast<STask<T>&>(roTasks[i]);
					oRetData[i] = t;
				}
			}
			co_return oRetData;
		}

		static STask<void> All(const std::vector<STask<void>>& roTasks)
		{
			UINT32 dwSize = (UINT32)roTasks.size();
			for (UINT32 i = 0; i != dwSize; ++i)
			{
				co_await const_cast<STask<void>&>(roTasks[i]);
			}
		}

		template<typename T1, typename T2>
		static STask<std::tuple<T1, T2>> All(const STask<T1>& rsTask1, const STask<T2>& rsTask2)
		{
			T1 t1 = co_await const_cast<STask<T1>&>(rsTask1);
			T2 t2 = co_await const_cast<STask<T2>&>(rsTask2);
			co_return { t1, t2 };
		}

		template<typename T1, typename T2, typename T3>
		static STask<std::tuple<T1, T2, T3>> All(const STask<T1>& rsTask1, const STask<T2>& rsTask2, const STask<T3>& rsTask3)
		{
			T1 t1 = co_await const_cast<STask<T1>&>(rsTask1);
			T2 t2 = co_await const_cast<STask<T2>&>(rsTask2);
			T3 t3 = co_await const_cast<STask<T3>&>(rsTask3);
			co_return { t1, t2, t3 };
		}
	};
}

#endif
